package com.bdqn.controller;

import com.bdqn.pojo.User;
import com.bdqn.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller

public class IndexController {
    @Resource
    private UserService userService;
    @RequestMapping("/login")
    public String login(){
        return "login";
    }
    @PostMapping("/doLogin")
    public String doLogin(String usrName, String usrPassword, HttpSession session, Model model){
        User user=userService.login(usrName,usrPassword);
        if(user!=null) {
            session.setAttribute("loginUser", user);
            return "main";
        }else {
            model.addAttribute("message", "账号或密码错误，请重新登录。");
            return "login";
        }
    }


}
